package com.ruoyi.yl.controller;


import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.domain.body.ActivityBody;
import com.ruoyi.common.domain.body.OrderBody;
import com.ruoyi.common.domain.dto.CommentDto;
import com.ruoyi.common.domain.dto.OrderDTO;
import com.ruoyi.yl.process.OrderProcess;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController extends BaseController {

    @Resource
    private OrderProcess orderProcess;

    @PostMapping("/create")
    public AjaxResult create(@RequestBody ActivityBody activityBody) {
        return AjaxResult.success(orderProcess.createOrder(activityBody));
    }

    @PostMapping("/pay/points")
    public AjaxResult payOrderPoints(@RequestBody OrderBody orderBody) {

        orderProcess.payOrderPoints(orderBody.getOrderNo());
        return AjaxResult.success();
    }

    @PostMapping("/list")
    public TableDataInfo selectOrderList(@RequestBody OrderBody orderBody) {
        startPage();
        List<OrderDTO> orderList = orderProcess.getOrderList(orderBody.getCurrentStatus());
        return getDataTable(orderList);
    }

    @PostMapping("/cancel/order")
    public AjaxResult CancelOrder(@RequestBody OrderBody orderBody) {

        orderProcess.CancelOrder(orderBody.getOrderNo());
        //这边要对退款退积分逻辑 但是可以先写退积分
        return AjaxResult.success();
    }

    @PostMapping("/get/commentInfo/byOrderNo")
    public AjaxResult getCommentInfoByOderNo(@RequestBody OrderBody orderBody) {
        //获取点评所需要信息通过orderNo
        CommentDto commentInfoByOderNo = orderProcess.getCommentInfoByOderNo(orderBody.getOrderNo());
        return AjaxResult.success(commentInfoByOderNo);
    }



}
